﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AlgoImpl.Constraints;
using Utilities;

namespace AlgoImpl
{
    public delegate void AlgoFinihedEventHandler();

    public class ShiftOrganizorManager
    {

        private StepManagerAbstract m_FirstStepManager;
        private StepManagerAbstract m_SecondStepManager;
        private StepManagerAbstract m_ThirdStepManager;
        public event AlgoFinihedEventHandler AlgoFinished;

        public ShiftOrganizorManager(ShiftRequests sr)
        {
            m_FirstStepManager = new StepOneManager(sr, (int)Math.Pow((double)sr.Request.Keys.Count, 2));
            m_SecondStepManager = new SecondStepManager(sr, 1);
            m_ThirdStepManager = new ThirdStepManager(sr, 1);
            ConstraintsChecker.Instance.Constraints.InitAsTrue();
        }

        private void onAlgoFinished()
        {
            if (AlgoFinished != null)
            {
                AlgoFinished.Invoke();
            }
        }


        public void OrganizeWorkersToShifts()
        {
            Logger.Instance.WriteToLog("analyzing first step");
            m_FirstStepManager.RunStep();
            m_SecondStepManager.AnalyzerMgr = m_FirstStepManager.AnalyzerMgr;
            Logger.Instance.WriteToLog("analyzing second step");
            m_SecondStepManager.RunStep();
            m_ThirdStepManager.AnalyzerMgr = m_SecondStepManager.AnalyzerMgr;
            Logger.Instance.WriteToLog("analyzing third step");
            m_ThirdStepManager.RunStep();
            FinalResultHolder.Instance.Print();
            //Logger.Instance.CloseLogger();
            onAlgoFinished();
        }
    }
}
